package com.yan.design.two.establish.s4.builder3;

import lombok.ToString;

import java.util.Arrays;
import java.util.List;

/**
 * 四.建造者模式
 *      建造者 - 链式编程
 * @author shengren.yan
 * @create 2022-07-17
 */
@ToString
public class Student {

    int id;
    int age;
    String name;
    List<String> awards;
    // .... 比如有很多

    public Student(int id, int age, String name, List<String> awards) {
        this.id = id;
        this.age = age;
        this.name = name;
        this.awards = awards;
    }

    public static StudentBuilder builder(){
        // 通过builder方法直接获取建造者
        return new StudentBuilder();
    }

    public static class StudentBuilder{
        int id;
        int age;
        String name;
        List<String> awards;

        public StudentBuilder id(int id){
            this.id = id;
            return this;
        }
        public StudentBuilder age(int age){
            this.age = age;
            return this;
        }
        public StudentBuilder name(String name){
            this.name = name;
            return this;
        }
        public StudentBuilder name(String... awards){
            this.awards = Arrays.asList(awards);
            return this;
        }
        // ...

        public Student build(){
            return new Student(id,age,name,awards);
        }
    }


    public static void main(String[] args) {

        Student s = Student.builder()
                .id(1)
                .name("2222")
                .build();

        System.out.println(s);
    }

}
